//
//  MDLoginViewController.m
//  MvvmDemo
//
//  Created by 吴伟城 on 2018/12/16.
//  Copyright © 2018 吴伟城. All rights reserved.
//

#import "MDLoginViewController.h"

@import Masonry;

@interface MDLoginViewController ()

@property (weak, nonatomic) id<MDLoginViewControllerDelegate> delegate;

@end

@implementation MDLoginViewController

- (instancetype)initWithDelegate:(id<MDLoginViewControllerDelegate>)delegate {
  if (self = [self init]) {
    _delegate = delegate;
  }
  return self;
}

- (void)viewDidLoad {
  [super viewDidLoad];
  [self makeUI];
}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  self.navigationController.navigationBarHidden = YES;
}

- (void)makeUI {
  self.view.backgroundColor = [UIColor whiteColor];
  
  UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  loginBtn.backgroundColor = [UIColor redColor];
  [loginBtn setTitle:@"Sign In" forState:UIControlStateNormal];
  [loginBtn addTarget:self action:@selector(loginAction:) forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:loginBtn];
  [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.leading.trailing.mas_equalTo(0);
  }];
  
  UIButton *registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  registerBtn.backgroundColor = [UIColor greenColor];
  [registerBtn setTitle:@"Sign Up" forState:UIControlStateNormal];
  [registerBtn addTarget:self action:@selector(registerAction:) forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:registerBtn];
  [registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.bottom.trailing.mas_equalTo(0);
    make.top.mas_equalTo(loginBtn.mas_bottom);
    make.height.mas_equalTo(loginBtn);
  }];
}

#pragma mark - View Actions

- (void)loginAction:(id)sender {
  if ([self.delegate respondsToSelector:@selector(loginViewControllerShouldShowHomeVC:)]) {
    [self.delegate loginViewControllerShouldShowHomeVC:self];
  }
}

- (void)registerAction:(id)sender {
  if ([self.delegate respondsToSelector:@selector(loginViewControllerShouldShowRegisterVC:)]) {
    [self.delegate loginViewControllerShouldShowRegisterVC:self];
  }
}

@end
